<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head th:replace="/common/include :: header(~{::title}, ~{::link}, ~{::style})">
	<title>日志监控-定时任务日志</title>
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<th:block th:include="/common/breadcrumb :: breadcrumb"/>
			<div class="col-sm-12 search-collapse">
				<form id="search-form">
					<div class="select-list row">
						<div class="col-sm-3 col-xs-6">
							<div class="control-label">任务名称：</div>
							<div><input class="form-control" type="text" name="Q_jobName_S_LK"/></div>
						</div>
						<div class="col-sm-3 col-xs-6">
							<div class="control-label">执行结果：</div>
							<div>
								<select class="form-control selectpicker" name="Q_status_S_EQ" th:with="type=${@dict.getDataGroup('sys_quartz_status')}">
									<option value="">全部</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</div>
						</div>
						<div class="col-sm-3 col-xs-6">
							<div class="control-label">开始时间：</div>
							<div class="select-time">
								<input type="text" class="form-control" id="startTime" placeholder="开始时间" name="Q_startTime_D_GE"/>
								<span>-</span>
								<input type="text" class="form-control" id="endTime" placeholder="结束时间" name="Q_startTime_D_LE"/>
							</div>
						</div>
						<div class="right-btn">
							<a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search('bootstrap-table', 'search-form')"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-default btn-rounded btn-sm" onclick="$.form.reset('search-form')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</div>
					</div>
				</form>
			</div>

            <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-primary" onclick="openSocket()">
					<i class="fa fa-plus"></i> 查看服务器日志
				</a>
				<a class="btn btn-default" onclick="downloadLog('0')">
					<i class="fa fa-download"></i> 下载服务器实时日志
				</a>
                <a class="btn btn-default" onclick="downloadLog('1')">
                    <i class="fa fa-download"></i> 下载服务器指定日志
                </a>
				<a class="btn btn-danger btn-del disabled" onclick="del()">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="delAll()">
					<i class="fa fa-remove"></i> 清空
				</a>
	        </div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
	    </div>
	</div>

	<div th:replace="/common/include :: footer"></div>

	<script th:inline="javascript">
		var status_data_list = [[${@dict.getDataGroup('sys_quartz_status')}]];
		var prefix = ctx + 'api/system/log';

		$(function() {
			// 加载日期组件
			$.form.renderDateRange('startTime', 'endTime');

            var options = {
                code: 'jobLogId',
                url: prefix + '/quartz/table',
                sortName: 'startTime',
                sortOrder: 'desc',
                search: false,
                showExport: false,
                pagination: true,
				rememberSelected: true,
                columns: [{
					field: 'rowState',
                    checkbox: true
                },
                    {
                        field: 'jobName',
                        title: '任务名称',
                        sortable: true
                    },
                    {
                        field: 'jobGroup',
                        title: '任务组名',
						formatter: function(value, row, index) {
							return $.common.render.ellipsis(value);
						}
                    },
					{
						field: 'methodName',
						title: '任务方法',
						formatter: function(value, row, index) {
							return $.common.render.ellipsis(value);
						}
					},
					{
						field: 'methodParam',
						title: '方法参数',
						formatter: function(value, row, index) {
							return $.common.render.ellipsis(value);
						}
					},
					{
						field: 'exceptionInfo',
						title: '异常信息',
						formatter: function(value, row, index) {
							return $.common.render.ellipsis(value);
						}
					},
					{
						field: 'startTime',
						title: '开始时间',
						sortable: true
					},
					{
						field: 'endTime',
						title: '结束时间',
						sortable: true
					},
					{
						field: 'execTime',
						title: '执行时间',
						sortable: true
					},
                    {
                        field: 'status',
                        title: '执行结果',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.common.dictLabel(status_data_list, value);
                        }
                    }]
            };
            $.table.init('bootstrap-table', options);
		});

		function del() {
            var url = prefix + '/quartz/delete';
			$.operate.removeSelect('bootstrap-table', url, '确定删除选中的数据吗？', 'table', 'refresh');
		}

		function delAll() {
			var url = prefix + '/quartz/delete';
			$.operate.remove(url, null, '确定删除全部数据吗？', 'refresh');
		}

		function refresh() {
		    $.table.refresh();
		}

        function openSocket() {
            var title = '进程日志';
            var url = ctx + 'api/log/poll';
            $.operate.edit({
                title: title,
                content: url,
                shadeClose: true,
                _index: window.name
            });
        }

        function downloadLog(type) {
		    if ('1' == type) {
                $.modal.lay.prompt('请输入日期（yyyy-MM-dd）', 'downloadUrl');
            } else {
		        downloadUrl();
            }
		}

		function downloadUrl(date) {
			if (date) {
				$.common.download(ctx + encodeURI('api/file/download?path=/usr/local/soft/apache-tomcat-8.5.43/logs/catalina.' + date + '.log') + '&delete=' + false);
			} else {
				date = getNowFormatDate();
				$.common.download(ctx + encodeURI('api/file/download?path=/usr/local/soft/apache-tomcat-8.5.43/logs/catalina.' + date + '.log') + '&delete=' + false);
			}
		}

		function getNowFormatDate() {
			var date = new Date();
			var seperator = "-";
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = year + seperator + month + seperator + strDate;
			return currentdate;
		}

	</script>
</body>
</html>